/*
 *  copy source from lua-5.1.4 to learn lua implementation
 */


#ifndef lconfig_h
#define lconfig_h

#include <limits.h>
#include <stddef.h>

#if defined(LUA_USE_POSIX)
#define LUA_USE_MKSTEMP
#define LUA_USE_ISATTY
#define LUA_USE_POPEN
#define LUA_USE_ULONGJMP
#endif

#if defined(__cplusplus)
/* C++ exceptions */
#define LUAI_THROW(L,c)	throw(c)
#define LUAI_TRY(L,c,a)	try { a } catch(...) \
	{ if ((c)->status == 0) (c)->status = -1; }
#define luai_jmpbuf	int  /* dummy variable */

#elif defined(LUA_USE_ULONGJMP)
/* in Unix, try _longjmp/_setjmp (more efficient) */
#define LUAI_THROW(L,c)	_longjmp((c)->b, 1)
#define LUAI_TRY(L,c,a)	if (_setjmp((c)->b) == 0) { a }
#define luai_jmpbuf	jmp_buf

#else
/* default handling with long jumps */
#define LUAI_THROW(L,c)	longjmp((c)->b, 1)
#define LUAI_TRY(L,c,a)	if (setjmp((c)->b) == 0) { a }
#define luai_jmpbuf	jmp_buf
#endif

#if defined(LUA_BUILD_AS_DLL)
#if defined(LUA_CORE) || defined(LUA_LIB)
#define LUA_API __declspec(dllexport)
#else
#define LUA_API __declspec(dllimport)
#endif

#else

#define LUA_API   extern

#endif

/* more often than not the libs go together with the core */
#define LUALIB_API  LUA_API

#define LUA_IDSIZE  60

//#define LUA_NUMBER_SCAN "%lf"
//#define LUA_NUMBER_FMT  "%.14g"
#define lua_number2str(s, n)  sprintf((s), LUA_NUMBER_FMT, (n))

#define LUAI_EXTRASPACE		0

#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; }

#if INT_MAX-20 < 32760
#define LUAI_BITSINT  16
#elif INT_MAX > 2147483640L
/* int has at least 32 bits */
#define LUAI_BITSINT  32
#else
#error "you must define LUA_BITSINT with number of bits in an integer"
#endif

#if LUAI_BITSINT >= 32
#define LUAI_UINT32 unsigned int
#define LUAI_INT32  int
#define LUAI_MAXINT32 INT_MAX
#define LUAI_UMEM size_t
#define LUAI_MEM  ptrdiff_t
#else
/* 16-bit ints */
#define LUAI_UINT32 unsigned long
#define LUAI_INT32  long
#define LUAI_MAXINT32 LONG_MAX
#define LUAI_UMEM unsigned long
#define LUAI_MEM  long
#endif

#if defined(luaall_c)
#define LUAI_FUNC static
#define LUAI_DATA /* empty */

#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
                                                                     defined(__ELF__)
#define LUAI_FUNC __attribute__((visibility("hidden"))) extern
#define LUAI_DATA LUAI_FUNC

#else
#define LUAI_FUNC extern
#define LUAI_DATA extern
#endif

#endif
